<!-- 申请弹窗 -->
<template>
  <el-dialog title="提交申请" :visible.sync="dialogFormVisible">
    <el-form :model="form">
      <el-form-item label="姓名" :label-width="formLabelWidth">
        <el-input v-model="form.name" autocomplete="off"></el-input>
      </el-form-item>
      <el-form-item label="年龄" :label-width="formLabelWidth">
        <el-input v-model="form.age" autocomplete="off"></el-input>
      </el-form-item>
      <el-form-item label="学校" :label-width="formLabelWidth">
        <el-input v-model="form.school" autocomplete="off"></el-input>
      </el-form-item>
      <el-form-item label="联系电话" :label-width="formLabelWidth">
        <el-input v-model="form.phone" autocomplete="off"></el-input>
      </el-form-item>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button @click="dialogFormVisible = false">取 消</el-button>
      <el-button type="primary" @click="submitForm()">确 定</el-button>
    </div>
  </el-dialog>
</template>
<script>
export default {
  data() {
    return {
      form: {
        name: "",
        age: "",
        school: "",
        phone: "",
        companyName: "",
        status: "0",
        userId: "",
        jobName: "",
        desprition: "",
        img: "",
        address: "",
      },
      formLabelWidth: "120px",
      dialogFormVisible: false,
    };
  },

  methods: {
    onShow(info) {
      
      this.dialogFormVisible = true;
      this.form.name = "";
      this.form.age = "";
      this.form.school = "";
      this.form.phone = "";
      this.form.companyName = info.conpanyName;
      this.form.status = "0";
      this.form.userId = "";
      this.form.jobName = info.title;
      this.form.desprition = info.desprition;
      this.form.img = info.cover_picture;
      this.form.address = info.address;

      this.getUserInfo();
    },

    // 获取用户信息
    getUserInfo() {
      this.$http.get(`/login/getinfo`).then((res) => {
        const { code, msg, result } = res;
        if (code == 0) {
          this.form.userId = result.id;
        }
      });
    },

    submitForm() {
      this.$http.post(`/apply`, this.form).then((res) => {
        if (res.code == 0) {
          this.$message({
            type: "success",
            message: "申请成功!",
          });
          this.dialogFormVisible = false;
        } else {
          this.$message({
            type: "info",
            message: "申请失败",
          });
        }
      });
    },
  },
};
</script>
<style>
</style>
